<?php

require_once('simpletest/unit_tester.php');
require_once('simpletest/reporter.php');

require_once('../post.php');

class PostTest extends UnitTestCase{
	
	const EMPTY_TITLE = "";
	const EMPTY_POST = "";
	const EMPTY_CATEGORY = ""; 
	
	const NON_EMPTY_TITLE = "unit test title";
	const NON_EMPTY_POST = "unit test post";
	const NON_EMPTY_CATEGORY = "unit test category";

	function test_addPostCorrectlyValidatesEmptyInputs(){
		
		$this->assertFalse(Post::addPost(PostTest::EMPTY_TITLE,PostTest::EMPTY_POST,PostTest::EMPTY_CATEGORY));
		$this->assertFalse(Post::addPost(PostTest::NON_EMPTY_TITLE,PostTest::EMPTY_POST,PostTest::NON_EMPTY_CATEGORY));
	}
	
	function test_addPostCorrectlyValidatesNonEmptyInputs(){
		
		$this->assertTrue(Post::addPost(PostTest::NON_EMPTY_TITLE,PostTest::NON_EMPTY_POST,
			PostTest::NON_EMPTY_CATEGORY));
	}
	
	function test_findAllPostsIsReturningAllPosts(){
		
		$numberOfPosts = Post::getNumberOfPosts();
		$this->assertEqual($numberOfPosts, sizeof(Post::findAllPosts()));
	}
	
	const CATEGORY_ID = "11";

	function test_getCategoryName(){
		
		$post = new Post("1", "title", "author", "entry", "date", PostTest::CATEGORY_ID);
		$this->assertEqual("category 4", $post->getCategoryName());
	}
	
	function test_errorsAreBeingAddedToErrorsArray(){

		Post::addPost(PostTest::EMPTY_TITLE,PostTest::EMPTY_POST,PostTest::EMPTY_CATEGORY);
		$this->assertEqual(3,count(Post::getErrors()));
	}
}
$test = &new PostTest();
$test->run(new HtmlReporter());
?>
